//
// DOM stands for Document Object Model
//
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class DOM
{
	// Holds all of the data as name/value pairs
	private HashMap<String, String> data = new HashMap<String, String>();

	private String source;

	public DOM(String file)
	{
		load(file);
	}

	public void load(String file)
	{
		File f = new File(file);
		BufferedReader read = null;
		try
		{
			read = new BufferedReader(new FileReader(f));
		}
		catch (Exception e)
		{
			System.out.println(f + " not found...");
			e.printStackTrace();
		}
		String line = null;
		do
		{
			try
			{
				line = read.readLine(); // does not include terminating \n
				if (line != null)
				{
					int space = line.indexOf(' ');
					String name = line.substring(0, space); // does not include
															// the index of the
															// space
					String value = line.substring(space + 1);
					//System.out.println(name + " = " + value);
					data.put(name, value);
				}
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}
		while (line != null);
	}

	public String getSource()
	{
		return source;
	}

	/**
	 * 
	 * @param named
	 *            the named of the parameter being retrieved
	 * @return the value from the DOM's file
	 */
	public String getString(String named)
	{
		return data.get(named);
	}

	/**
	 * 
	 * @param named
	 *            the name of the parameter being retrieved
	 * @return the value from the DOM's file as an integer
	 */
	public int getValue(String named)
	{
		return Integer.parseInt(getString(named));
	}
}
